package com.taskcollection.service;

import com.taskcollection.bean.ProjectProgressBean;
import com.taskcollection.mapper.ProjectProgress;
import com.taskcollection.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;


import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by haocongshun on 2016/8/4.
 */
public class ProjectProgressService {
    private ProjectProgress pp;

    public ProjectProgress getPp() {
        return pp;
    }

    public void setPp(ProjectProgress pp) {
        this.pp = pp;
    }

    public List<ProjectProgressBean> getAll(String project_id){
            return pp.getAll(project_id);
    }
    public String getProject_id(String student_id){
            return pp.getProject_id(student_id);
    }
    public boolean del(String projectProgress_id){
            boolean flag = pp.del(projectProgress_id);
           return flag;
    }
    public boolean add(Map<String ,String > result,String student_id){
        ProjectProgressBean ppb = new ProjectProgressBean();
        ppb.setProjectProgress_id(ServiceUtil.getPK("projectProgress_id","projectProgress"));
        ppb.setProjectProgress_name(result.get("name"));
        ppb.setProjectProgress_content(result.get("content"));
        Date date = new Date();
        ppb.setProjectProgress_date((new java.sql.Timestamp(date.getTime())).toString());
        ppb.setProjectProgress_file(result.get("file"));
        ppb.setProject_id(result.get("project_id"));
        ppb.setStudent_id(student_id);
            boolean flag = pp.add(ppb);
            return flag;

    }
    public ProjectProgressBean getById(String projectProgress_id){
        SqlSession sqlSession = MybatisUtil.getinstance().getFactory().openSession();
        try {
            ProjectProgress pp = sqlSession.getMapper(ProjectProgress.class);
            return pp.getById(projectProgress_id);
        }finally {
            sqlSession.close();
        }
    }
}
